package com.cff.pm.handler;

import java.io.IOException;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.cff.pm.util.HttpUtil;
import com.cff.pm.util.Md5Util;

public class WeixinMessageHandler {
	private String businessId;
	private String salt;
	private String url;
	private List<String> recipients;

	WeixinMessageHandler(String businessId, String salt, String url, List<String> recipients) {
		this.businessId = businessId;
		this.salt = salt;
		this.url = url;
		this.recipients = recipients;
	}

	public void sendMessage(String content) throws IOException {
		JSONObject json = new JSONObject();
		json.put("businessId", businessId);
		json.put("content", content);
		json.put("recipients", recipients);
		String sign = Md5Util.md5(businessId + content + salt);
		json.put("sign", sign);
		HttpUtil.doJsonPost(url, json.toJSONString());
	}

	public String getBusinessId() {
		return businessId;
	}

	public void setBusinessId(String businessId) {
		this.businessId = businessId;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public List<String> getRecipients() {
		return recipients;
	}

	public void setRecipients(List<String> recipients) {
		this.recipients = recipients;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}
